<template>
  <div class="detail">
    <Header :detailData="detailData" />
    <ToBuy v-if="$store.state.isToBuy" :detailData="detailData"></ToBuy>
    <Footer v-else class="footer" :detailData="detailData"/>
  </div>
</template>

<script>
import ToBuy from "@/components/detail/Detail_buy.vue";
import Header from "@/components/detail/Detail_head.vue";

import Footer from "@/components/detail/Detail_footer.vue";
import { HomeShowGoodsApi } from "@/request/api";
export default {
  data() {
    return {
      detailData: [],
      goodsId: null,
    };
  },
  components: {
    Header,
    ToBuy,
    Footer,
  },
  mounted() {
    // 查询detail
    // const {goodsId}=this.$route.params
    // console.log(goodsId);
    // this.HomeShowGoodsApi(goodsId)
  },
  created() {
    const { goodsId, goodsName } = this.$route.params;
    this.goodsId = goodsId;
    console.log(goodsId);
    HomeShowGoodsApi({
      goodsId: goodsId,
    }).then((res) => {
      let arr = res.data.data;
      console.log(arr);
      console.log(goodsId);
      arr.filter((item) => {
        if (item.goodsId == goodsId) {
          this.detailData = item;
          console.log(this.detailData);
        }

        return this.detailData;
      });
    });

    console.log(goodsId);
  },
  methods: {
    // 查询商品详情
  },
};
</script>
 
<style lang = "less" scoped>
.detail {
  position: relative;
  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 9;
  }
}
</style>